package com.common.utils;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HbaseOSUtils {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(HbaseOSUtils.class);

	// 兼容windows访问hbase
	public static final void hackForWin() {
		if (SystemUtils.IS_OS_WINDOWS) {
			File workaround = new File(".");
			System.getProperties().put("hadoop.home.dir",
					workaround.getAbsolutePath());
			File binDir = new File(".\\bin");
			if (!binDir.exists()
					|| !binDir.isDirectory())
			{
				FileUtils.deleteQuietly(binDir);
				binDir.mkdirs();
			}
			
			try {
				File winUtilsFile = new File(".\\bin\\winutils.exe");
				if (!winUtilsFile.exists()
						|| !winUtilsFile.isFile())
				{
					FileUtils.deleteQuietly(winUtilsFile);
					winUtilsFile.createNewFile();
				}
			} catch (IOException e) {
				LOGGER.error("", e);
			}
		}
	}
}
